#include "global.h"

QString bytesToSize(qint64 size)
{
    if (size < 0)
        return QString();
    if (size < 1024)
        return QString::number(((double)size), 'f', 2).append(QObject::tr(" B"));
    if ((size >= 1024) && (size < 1048576))
        return QString::number(((double)size)/1024, 'f', 2).append(QObject::tr(" KB"));
    if ((size >= 1048576) && (size < 1073741824))
        return QString::number(((double)size)/1048576, 'f', 2).append(QObject::tr(" MB"));
    if (size >=1073741824)
        return QString::number(((double)size)/1073741824, 'f', 2).append(QObject::tr(" GB"));
    return QString();
}

QString statusToString(UploadStatus status)
{
    switch (status) {
        case UploadNewStatus:
            return QObject::tr("New");
        case UploadInProgressStatus:
            return QObject::tr("Uploading");
        case UploadDoneStatus:
            return QObject::tr("Ready");
        case UploadErrorStatus:
            return QObject::tr("Error");
        case UploadAbortedStatus:
            return QObject::tr("Aborted");
    }
    return QString();
}

QString statusToString(DownloadStatus status)
{
    switch (status) {
        case DownloadNewStatus:
            return QObject::tr("New");
        case DownloadInProgressStatus:
            return QObject::tr("Downloading...");
        case DownloadDoneStatus:
            return QObject::tr("Done");
        case DownloadErrorStatus:
            return QObject::tr("Error");
        case DownloadAbortedStatus:
            return QObject::tr("Aborted");
        case DownloadPausedStatus:
            return QObject::tr("Paused");
        case DownloadWaitStatus:
            return QObject::tr("Waiting");
    }
    return QString();
}
